--- title: "1、日期统计" created: 2025-11-28 tags: - 算法 --- # 1、日期统计 ## 题目 [日期统计](https://www.lanqiao.cn/paper/3818/problem/3492/) ![[image-22ba0b4b.png]] ``` 5 6 8 6 9 1 6 1 2 4 9 1 9 8 2 3 6 4 7 7 5 9 5 0 3 8 7 5 8 1 5 8 6 1 8 3 0 3 7 9 2 7 0 5 8 8 5 7 0 9 9 1 9 4 4 6 8 6 3 3 8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4 0 1 0 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3 ``` ## 思路分析 子序列 不连续的也是子序列 比如 abcdef 其中bdf也是他的一个子序列 如果是连续的话 这题就比较好写 滑动窗口截断八个即可 再拿得到的字符串去检查是否为合法日期以及是否在2023年内 ```cpp #include using namespace std; const int N=110; int a[N]; int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool isleap(int y){ return y%100 && y%4==0 || y%400==0; } int getdays(int y,int m){ return days[m]+(m==2 && isleap(y)); } bool checkdate(int y,int m,int d){ if(m<1 || m>12) return false; if(d<1 || d>getdays(y,m)) return false; return true; } int main() { int n=100; for(int i=0;i>a[i]; int cnt=0; for(int i=7;i using namespace std; const int N=110; char a[N]; int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool isleap(int y){ return y%100 && y%4==0 || y%400==0; } int getdays(int y,int m){ return days[m]+(m==2 && isleap(y)); } void nextday(int &y,int &m,int &d){ d++; if(d>getdays(y,m)){ d=1; m++; if(m>12){ m=1; y++; } } } //bool checkdate(int y,int m,int d){ // if(m<1 || m>12) return false; // if(d<1 || d>getdays(y,m)) return false; // return true; //} //在a串中 找是否出现子序列s bool check(char *s){ int big=100,small=8; int j=0; for(int i=0;i>a[i]; int cnt=0; int cury=2023,curm=1,curd=1; while(cury<2024){ // cout<